package com.winshare.saleAssistant.controller;

import com.winshare.saleAssistant.domain.dto.req.*;
import com.winshare.saleAssistant.service.OrganizationService;
import com.winshare.saleAssistant.util.LogicResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;

@RestController
@RequestMapping("/sys/org")
@CrossOrigin
@Api(value = "机构管理", description = "机构管理")
public class OrganizationController {

    private final OrganizationService organizationService;

    public OrganizationController(OrganizationService organizationService) {
        this.organizationService = organizationService;
    }

    @PostMapping("/save")
    @ApiOperation(value = "新增机构接口",notes = "新增机构接口")
    public LogicResponse save(@RequestBody @Validated OrganizationCreateDTO organizationCreateDTO) {
        organizationService.save(organizationCreateDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改机构接口",notes = "修改机构接口")
    public LogicResponse update(@RequestBody @Validated OrganizationUpdateDTO organizationUpdateDTO) {
        organizationService.update(organizationUpdateDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除机构接口",notes = "修改机构接口")
    public LogicResponse update(@RequestBody @Validated OrganizationDeleteDTO organizationUpdateDTO) {
        organizationService.delete(organizationUpdateDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/list")
    @ApiOperation(value = "获取机构列表", notes = "获取机构列表")
    public LogicResponse queryOrganizationPage(@RequestBody @Validated  OrganizationQueryDTO reqDTO) {
        return LogicResponse.success(organizationService.getOrganizationList(reqDTO));
    }

    @PostMapping("/detail")
    @ApiOperation(value = "获取单个机构详情")
    public LogicResponse getOrganizationDetail(@RequestBody @Validated BaseIdDTO baseIdDTO) {
        return LogicResponse.success(organizationService.getOrganizationDetail(baseIdDTO));
    }

    @PostMapping("/childOrgIdList")
    @ApiOperation(value = "通过一个机构id获取其所有的父机构id的集合")
    public LogicResponse getChildrenOrgList(@RequestBody @Validated BaseIdDTO baseIdDTO) {
        return LogicResponse.success(organizationService.getChildrenOrgList(baseIdDTO.getId(),null));
    }
}
